// 格式化日期为 "X月X日" 或 "X年X月X日"
export function formatDisplayDate(dateStr: string): string {
    const date = new Date(dateStr);
    const now = new Date();
    const year = date.getFullYear();
    const isThisYear = year === now.getFullYear();

    const month = date.getMonth() + 1;
    const day = date.getDate();

    return isThisYear
        ? `${month}月${day}日`
        : `${year}年${month}月${day}日`;
}

// 将形如20250411110000的字符串转换为 "11:00"
export function formatDisplayDateTime(dataTimeStr: string|undefined) : string {
    if (!dataTimeStr) {
        return "";
    }
    const hour = dataTimeStr.slice(8, 10);
    const minute = dataTimeStr.slice(10, 12);
    return `${hour}:${minute}`;
}

// 将GMT时间转化为北京时间 2025-04-11T10:00:07.986247878
export function convertToBeijingTime(gmtTime: string): string {
    const date = new Date(gmtTime);
    const beijingDateTime = new Date(date.getTime() + 8 * 60 * 60 * 1000); // 北京时间比GMT快8小时
    const hours = String(beijingDateTime.getHours()).padStart(2, '0');
    const minutes = String(beijingDateTime.getMinutes()).padStart(2, '0');
    const seconds = String(beijingDateTime.getSeconds()).padStart(2, '0');
    return `${hours}:${minutes}:${seconds}`;
}
